import React from 'react';
import actionCreators from '../store/actionCreators/counter2';
import {useSelector,useDispatch} from 'react-redux';
function Counter2(){
    //通过useSelector自定义Hook可以方便的获取状态的一部分 从仓库中读状态
    //state=rootState={counter1:{number:0},counter2:{number:0}}
    const counter2 = useSelector(state=>state.counter2);//mapStateToProps
    //获取到store.dispatch方法，通过派发动作的方式修改仓库中的状态
    const dispatch = useDispatch();
    return (
        <div>
            <p>{counter2.number}</p>
            <button onClick={()=>dispatch(actionCreators.add2())}>+</button>
            <button onClick={()=>dispatch(actionCreators.minus2())}>-</button>
        </div>
    )
}
export default Counter2;